package modulo1.cgd;

import java.util.List;
import javax.persistence.Query;
import modulo1.cdp.EnumEstadoTurma;
import modulo1.cdp.Turma;

public class TurmaDaoJpa extends DaoJpa<Turma> {

    public List<Turma> buscarAno(int ano) throws Exception {
        try {
            Query q = em.createQuery("SELECT t FROM Turma t WHERE t.ano = " + ano + " ORDER BY t.periodo DESC");
            return q.getResultList();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Turma> buscarAberta() throws Exception {
        try {
            Query q = em.createQuery("SELECT t FROM Turma t WHERE t.estado = :estado ORDER BY t.periodo DESC");
            q.setParameter("estado", EnumEstadoTurma.ABERTA);
            return q.getResultList();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Turma> buscarLiberada() throws Exception {
        try {
            Query q = em.createQuery("SELECT t FROM Turma t WHERE t.estado = :estado ORDER BY t.periodo DESC");
            q.setParameter("estado", EnumEstadoTurma.INICIADA);
            return q.getResultList();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Turma> buscarEncerrada() throws Exception {
        try {
            Query q = em.createQuery("SELECT t FROM Turma t WHERE t.estado = :estado ORDER BY t.periodo DESC");
            q.setParameter("estado", EnumEstadoTurma.ENCERRADA);
            return q.getResultList();
        } catch (Exception ex) {
            throw ex;
        }
    }
}